import 'package:flutter/material.dart';
import '../helloWord/hero_Page.dart';
import '../pages/search_page.dart';
import '../pages/form_page.dart';
import '../pages/default_page.dart';

//1、定义Map类型的routes
final Map routes = {
  '/': (context) => const DefaultPage(),
  '/search': (context) => const SearchPage(),
  '/form': (context, {arguments}) => FormPage(arguments: arguments),
  '/hero': (context, {arguments}) => HeroPage(arguments: arguments),
};

//2、调用onGenerateRoute处理
var onGenerateRoute = (RouteSettings settings) {
// 统一处理
  final String? name = settings.name;
  final Function? pageContentBuilder = routes[name];
  if (pageContentBuilder != null) {
    if (settings.arguments != null) {
      final Route route = MaterialPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
    } else {
      final Route route =
          MaterialPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  }
  return null;
};
